package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.SupplierEntity3;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;
import com.swgk.core.util.MToast;

public class GoodsDetailPriceDialog3 extends BaseBottomDialog {

    private SupplierEntity3 supplierEntity3;
    private DialogClickCallBack dialogClickCallBack;
    private TextView cancelView;
    private TextView okView;
    private TextView priceView;
    private TextView unitView;
    private TextView currentUnitView;
    private EditText modifyText;
    private String price = "";
    private String prePrice = "";

    public GoodsDetailPriceDialog3(Context context, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
    }

    public GoodsDetailPriceDialog3(Context context, int theme, DialogCallBack dialogCallBack) {
        super(context, theme, dialogCallBack);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.goods_detail_price_dialog3;
    }

    @Override
    protected void initView(DialogViewHolder holder,Bundle savedInstanceState) {
        modifyText = holder.getDialog().findViewById(R.id.modify_text);
        cancelView = holder.getDialog().findViewById(R.id.cancel_view);
        okView = holder.getDialog().findViewById(R.id.ok_view);
        priceView = holder.getDialog().findViewById(R.id.price_view);
        unitView = holder.getDialog().findViewById(R.id.unit_view);
        currentUnitView = holder.getDialog().findViewById(R.id.current_unit_view);
        cancelView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        okView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                price = modifyText.getText().toString();
                if (price.equals("")) {
                    MToast.showToast(getContext(), "价格不能为空!");
                    return;
                }
                if (dialogClickCallBack != null) {
                    dialogClickCallBack.onClickResult(price);
                }
                dismiss();
            }
        });
    }

    public GoodsDetailPriceDialog3 setPrice(String prePrice) {
        this.prePrice = prePrice;
        priceView.setText("¥ " + prePrice);
        return this;
    }

    public GoodsDetailPriceDialog3 setUnit(String unit) {
        unitView.setText("/" + unit);
        currentUnitView.setText("/" + unit);
        return this;
    }

    public interface DialogClickCallBack {
        void onClickResult(String price);
    }

    public GoodsDetailPriceDialog3 setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }
}
